<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数据绑定</title>
    <script type="text/javascript" src="../js/jquery-3.4.1.min.js"></script>
    <script>
        $(function(){
            $("#btn").click(function(){
                $(this).data("id",1);
                $(this).data("name","admin");
            });
            $("#btn2").click(function(){
                console.log($("#btn").data("id"))
                console.log($("#btn").data("name"))
                console.log($("#btn2").data("name"))
            });
            $("#btn3").click(function(){
                $("#btn").removeData("id");
            });
            $("#btn4").click(function(){
                // 修改就是添加,当key相同时会覆盖原有的数据
                $("#btn").data("id",2);
                $("#btn").data("name","alice");
            });
        })
    </script>
</head>
<body>
<button id="btn">数据绑定</button>
<button id="btn2">取值</button>
<button id="btn3">删除</button>
<button id="btn4">修改</button>
</body>
</html>